package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: itheima
 * @create: 2021-12-20 12:05
 */
@Api(value = "自媒体微服务频道管理")
@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {


    @Autowired
    private IWmChannelService wmChannelService;

    /**
     * 根据名称模糊查询分页列表
     *
     * @param dto 包含频道名称，分页信息
     * @return 频道分页列表
     */
    @PostMapping("/list")
    @ApiOperation("根据名称模糊查询分页列表")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        return wmChannelService.listByName(dto);
    }

    /**
     * 保存频道
     * @param entity
     * @return
     */
    @PostMapping
    public ResponseResult saveChannel(@RequestBody WmChannel entity){
        return wmChannelService.saveChannel(entity);
    }


    @GetMapping("/channels")
    public ResponseResult list(){
        //TODO 改为查询自定义业务方法 增加查询条件状态 排序order
        return ResponseResult.okResult(wmChannelService.list());
    }
}
